using System.Net.Sockets;
using HslCommunication;
using HslCommunication.Profinet.Melsec;

namespace HslCommunicationEx.HslNet
{
	public class MelsecMcNetEx : MelsecMcNet, IConnectState
	{
		public bool IsConnected => base.CoreSocket?.Connected ?? false;

		public MelsecMcNetEx()
		{
		}

		public MelsecMcNetEx(string ipAddress, int port)
			: base(ipAddress, port)
		{
		}

		public new OperateResult ConnectServer()
		{
			return base.ConnectServer();
		}

		public new void Dispose()
		{
			Socket coreSocket = base.CoreSocket;
			if (coreSocket != null && coreSocket.Connected)
			{
				base.CoreSocket.Shutdown(SocketShutdown.Both);
				base.CoreSocket.Disconnect(reuseSocket: false);
				base.CoreSocket.Close();
			}
		}
	}
}
